<?php

// $Id$

require_once(TANGRA_MAIN_DIR.'form/guardable_form.class.php');
require_once(TANGRA_MAIN_DIR.'form/fields/integer_positive/form_field_integer_positive.class.php');
require_once(TANGRA_MAIN_DIR.'form/fields/integer_limited/form_field_integer_limited.class.php');
require_once(TANGRA_MAIN_DIR.'form/fields/text/form_field_text.class.php');
require_once(TANGRA_MAIN_DIR.'form/fields/checkbox/form_field_checkbox.class.php');
require_once(TANGRA_MAIN_DIR.'form/fields/number/form_field_number.class.php');
require_once(TANGRA_MAIN_DIR.'/form/static_html_form_generator.class.php');


class Settings_Images_Form extends Guardable_Form {
	function __construct() {
		parent::__construct('settings_images', 'admin/modules/tangra_cms/settings/settings_content_edit.php');

		$f_allowed_extensions = new Form_Field_Text('allowed_extensions', true, 255);
		$this->add_field($f_allowed_extensions);

		$f_to_size_x = new Form_Field_Integer_Positive('to_size_x', false, true, 6);
		$this->add_field($f_to_size_x);

		$f_to_size_y = new Form_Field_Integer_Positive('to_size_y', false, true, 6);
		$this->add_field($f_to_size_y);

		$f_jpg_quality = new Form_Field_Integer_Limited('jpg_quality', 1, 99, true, 2, 80);
		$this->add_field($f_jpg_quality);

		$f_bgcolor = new Form_Field_Text('bgcolor', true, 6);
		$f_bgcolor->add_potential_error('invalid_value');
		$this->add_field($f_bgcolor);

		$f_keep_original = new Form_Field_Checkbox('keep_original', true, false);
		$this->add_field($f_keep_original);

		$f_thumbnail1_size_x = new Form_Field_Integer_Positive('thumbnail1_size_x', true, true, 6);
		$this->add_field($f_thumbnail1_size_x);

		$f_thumbnail1_size_y = new Form_Field_Integer_Positive('thumbnail1_size_y', true, true, 6);
		$this->add_field($f_thumbnail1_size_y);

		$f_thumbnail2_size_x = new Form_Field_Integer_Positive('thumbnail2_size_x', true, true, 6);
		$this->add_field($f_thumbnail2_size_x);

		$f_thumbnail2_size_y = new Form_Field_Integer_Positive('thumbnail2_size_y', true, true, 6);
		$this->add_field($f_thumbnail2_size_y);

		$f_maximum_size = new Form_Field_Integer_Positive('maximum_size', false, true, 12);
		$this->add_field($f_maximum_size);

		$f_maximum_size_x = new Form_Field_Integer_Positive('maximum_size_x', false, true, 6);
		$this->add_field($f_maximum_size_x);

		$f_maximum_size_y = new Form_Field_Integer_Positive('maximum_size_y', false, true, 6);
		$this->add_field($f_maximum_size_y);

		$f_minimum_ratio_xy = new Form_Field_Number('minimum_ratio_xy', true, 6);
		$this->add_field($f_minimum_ratio_xy);

		$f_maximum_ratio_xy = new Form_Field_Number('maximum_ratio_xy', true, 6);
		$this->add_field($f_maximum_ratio_xy);

		$f_watermark_image = new Form_Field_Text('watermark_image', false, 255);
		$this->add_field($f_watermark_image);

		$f_watermark_position = new Form_Field_Integer_Positive('watermark_position', true, false, 1);
		$this->add_field($f_watermark_position);

		$f_upload_path = new Form_Field_Text('upload_path', false, 255);
		$f_upload_path->add_potential_error('invalid_path');
		$this->add_field($f_upload_path);
	}


	public function generate_html() {
		$html_gen = new Static_HTML_Form_Generator($this, 'modules/form_html_tpl_static_ajax_metallic_en', 'en');
		$html_gen->create_default_tpl_maps();
		$html_gen->change_field_p_error_map_entry('bgcolor', 'invalid_value', 'modules/tangra_cms/forms/field_errors/settings_images/field_error_invalid_value.tpl');
		$html_gen->change_field_p_error_map_entry('upload_path', 'invalid_path', 'modules/tangra_cms/forms/field_errors/settings_images/field_error_invalid_path.tpl');

		printbr('<pre>');
		printbr(htmlentities($html_gen->get_static_html()));
		printbr('</pre>');
	}
}

